/**
 * Created by WYH on 17/4/24.
 */
angular.module('rentList', []).component(
    'rentList',
    {
        templateUrl: 'component/rent/rentList/rent_list.template.html',
        controller: [
            '$scope', '$state',
            function ($scope, $state) {

                $scope.headers = ['', '公司名称', '房间号', '租期截止', '代缴日期', '缴租状态', '操作'];

                $scope.mouseMoveRent = mouseMoveRent;
                $scope.clickRent = clickRent;
                $scope.showRentDetail = showRentDetail;
                $scope.showRentAuthWindow = showRentAuthWindow;
                $scope.showRentCancelAuthWindow = showRentCancelAuthWindow;
                $scope.leaveFocusStaffInformation = leaveFocusStaffInformation;
                $scope.changeSelectedclass=changeSelectedclass;

                getFocus();
                function getFocus() {
                    $("*").click(function (event) {
                        if (!$(this).hasClass('reli-selected-tbody')) {
                            $scope.selectRentProtocol = 'balck'
                            $scope.$apply(function () {
                                changeSelectedclass(null)
                            })
                        }
                        event.stopPropagation();
                    })
                }

                function showRentAuthWindow() {
                    $scope.$parent.showRentAuth = true;
                }

                function showRentCancelAuthWindow() {
                    $scope.$parent.showRentCancelAuth = true;
                }

                function mouseMoveRent(rent) {
                    $scope.hoverRentProtocol = rent;
                }

                function leaveFocusStaffInformation(rent) {
                    $scope.hoverRentProtocol = !rent;
                }

                function clickRent(rent) {
                    $scope.selectRentProtocol = rent;
                    $scope.$parent.selectRentProtocol = rent;
                }

                function changeSelectedclass(staff) {
                    if (staff == $scope.selectRentProtocol) {
                        return 'staff-triangl-select-img';
                    }
                    else if (staff == $scope.hoverRentProtocol) {
                        return 'staff-triangl-hover-img';
                    } else if ($scope.selectRentProtocol == 'balck') {
                        return '';
                    }
                    else {
                        return '';
                    }
                }

                function showRentDetail(rent) {
                    $state.go('company.managerRentDetail', {companyId: rent.companyId});
                }

            }
        ]
    }
);